package lex;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.StringReader;
import java.util.Collection;


public class Lexer
{

	public void process(String text, 
			Collection<Token> out_tokens) throws Exception
	{
		
		FileReader fr = new FileReader(text);
		BufferedReader br = new BufferedReader(fr); 
		String temp = br.readLine();		
		String wholeFile = "";
		
		while(temp!=null){
			wholeFile += temp + "\n";
			temp = br.readLine();
		}
				
		Scanner scanner = new Scanner(new StringReader(wholeFile));
		
		Token token = scanner.yylex();
        while (token != null) {
        	
        	if(token.errorCode==0){
        		out_tokens.add(token);
        	}else{
        		out_tokens.add(token);
        		break;
        	}
            token = scanner.yylex();
        }
		
       
		br.close();
        fr.close();
	}
}
